//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.mapper;

import com.example.entity.Activityapplication;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface ActivityapplicationMapper {
    List<Activityapplication> selectAll(Activityapplication activityapplication);

    @Select({"select * from activityapplication where id = #{id}"})
    Activityapplication selectById(Integer id);

    @Insert({"insert into activityapplication (activity_id, student_id, contact, remark, apply_time, status) values (#{activityId}, #{studentId}, #{contact}, #{remark}, now(), '待审核')"})
    int insert(Activityapplication activityapplication);

    @Update({"update activityapplication set president_id = #{presidentId}, content = #{content}, apply_time = #{applyTime}, title = #{title}, status = #{status}, club_id = #{clubId}, student_id = #{studentId} where id = #{id}"})
    int updateById(Activityapplication activityapplication);

    @Delete({"delete from activityapplication where id = #{id}"})
    int deleteById(Integer id);

    /**
     * 根据活动ID查询报名列表
     * @param activityId 活动ID
     * @return 报名列表
     */
    @Select("SELECT aa.*, s.name as studentName FROM activityapplication aa " +
            "LEFT JOIN student s ON aa.student_id = s.id " +
            "WHERE aa.activity_id = #{activityId}")
    List<Activityapplication> selectByActivityId(Integer activityId);

    /**
     * 更新报名状态
     * @param activityapplication 报名信息
     */
    @Update("UPDATE activityapplication SET status = #{status} WHERE id = #{id}")
    void updateStatus(Activityapplication activityapplication);

    /**
     * 检查学生是否已报名某个活动
     * @param activityId 活动ID
     * @param studentId 学生ID
     * @return 报名记录（如果存在），否则返回 null
     */
    @Select("SELECT * FROM activityapplication WHERE activity_id = #{activityId} AND student_id = #{studentId} LIMIT 1")
    Activityapplication checkApplicationExistsForActivity(@Param("activityId") Integer activityId, @Param("studentId") Integer studentId);
}
